<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	template="/layout/templateAdmin.xhtml">


	<ui:define name="head">

	</ui:define>	

	<ui:define name="conteudo" >
		<h:form id="formPrincipal">
			<p:panelGrid columns="2">
			<p:outputLabel value="Grupo:"/>

			<p:selectOneMenu value="#{UsuarioMb.obj.grupo.id}">
				<f:selectItems value="#{UsuarioMb.comboGrupo}"
				var="item" itemLabel="#{item.descricao}" itemValue="#{item.id}" />
			</p:selectOneMenu>
			
			<p:outputLabel value="Usuário:"/>
			<p:inputText value="#{UsuarioMb.obj.usuario}" label="Usuario"
			required="true" requiredMessage="Usuário Obrigatório"
			size="50" maxlength="50"/>
			
			<p:outputLabel value="Nome:"/>
			<p:inputText value="#{UsuarioMb.obj.nome}" requiredMessage="Nome Obrigatório"
			size="50" maxlength="50"/>
			
			<p:outputLabel value="Senha:"/>
			<p:inputText value="#{UsuarioMb.obj.senha}" redisplay="true" requiredMessage="Senha Obrigatório"
			size="50" maxlength="50"/>
			
			<p:outputLabel value="Email:"/>
			<p:inputText  value="#{UsuarioMb.obj.email}" requiredMessage="Senha Obrigatório"
			size="50" maxlength="50"/>
			
			<p:outputLabel value="Enviar Email:"/>
			<p:selectOneMenu value="#{UsuarioMb.obj.enviar_email}">
				<f:selectItems value="#{UsuarioMb.comboSimNao}" />
			</p:selectOneMenu>
			
			<p:outputLabel value="Ativo:"/>
			<p:selectOneMenu value="#{UsuarioMb.obj.ativado}">
				<f:selectItems value="#{UsuarioMb.comboSimNao}" />
			</p:selectOneMenu>	
			
			</p:panelGrid>
			
			
		<div class="boxComponentes">
		<div class="box_botoes" style="margin-top: 13px;">
		<p:commandButton value="Inserir" actionListener="#{UsuarioMb.inserir()}"
			 update=":formDados :growl :formPrincipal" icon="ui-icon-disk"
			 rendered="#{empty UsuarioMb.obj.id}"/>
		 
		 <p:commandButton value="Alterar" actionListener="#{UsuarioMb.alterar}"
		 	update=":formDados :growl :formPrincipal" icon="ui-icon-pencil"
		 	rendered="#{not empty UsuarioMb.obj.id}"/>
		 
		 <p:commandButton value="cancelar" actionListener="#{UsuarioMb.limpar}"
			 update=":formDados :growl :formPrincipal" icon="ui-icon-cancel"
			 rendered="#{not empty UsuarioMb.obj.id}"/>
		 
		 <p:commandButton value="Excluir" onclick="modalExclusao.show()"
			 icon="ui-icon-trash" rendered="#{not empty UsuarioMb.obj.id}"/>
		</div>
	</div>	
		</h:form>	
			
		<h:form id="formDados">
			<p:dataTable id="lista" value="#{UsuarioMb.lista}"
						var="obj" rowKey="#{obj.id}" paginator="true"
						rows="5" selectionMode="single"
						paginatorPosition="bottom" emptyMessage="Nenhum item encontrado">
						
		<p:ajax event="rowSelect" listener="#{UsuarioMb.selecionar}"
			update=":formPrincipal"/>				
						
				<p:column sortBy="#{obj.grupo.descricao}">
					<f:facet name="header">GRUPO</f:facet>
					<h:outputText value="#{obj.grupo.descricao}" />
				</p:column>
				<p:column sortBy="#{obj.usuario}">
					<f:facet name="header">USUARIO</f:facet>
					<h:outputText value="#{obj.usuario}" />
				</p:column>
				<p:column sortBy="#{obj.nome}">
					<f:facet name="header">NOME</f:facet>
					<h:outputText value="#{obj.nome}" />
				</p:column>
				<p:column sortBy="#{obj.email}">
					<f:facet name="header">EMAIL</f:facet>
					<h:outputText value="#{obj.email}" />
				</p:column>
				<p:column sortBy="#{obj.enviar_email}" style="text-align: center">
					<f:facet name="header">ENVIAR EMAIL</f:facet>
					<p:commandLink actionListener="#{UsuarioMb.alterarEnviarEmail(obj)}"
					update=":formDados :growl">
					<h:graphicImage value="/imagens/icones/Yes.png" rendered="#{obj.enviar_email eq 'S'}" />
					<h:graphicImage value="/imagens/icones/No.png" rendered="#{obj.enviar_email eq 'N'}" />	
					</p:commandLink>				
				</p:column>
				<p:column sortBy="#{obj.ativado}" style="text-align: center">
					<f:facet name="header">ATIVO</f:facet>
					<p:commandLink actionListener="#{UsuarioMb.alterarAtivado(obj)}"
					update=":formDados :growl">
					<h:graphicImage value= "/imagens/icones/Yes.png" rendered="#{obj.ativado eq 'S'}" />
					<h:graphicImage value= "/imagens/icones/No.png" rendered="#{obj.ativado eq 'N'}" />
					</p:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
		
		 <p:confirmDialog id="confirmExclusao" message="Excluir"
	   		appendToBody="true" header="Atenção" severity="alert"
	   		widgetVar="modalExclusao">
	     <h:form id="formConfirmacao">
	   		<p:commandButton value="Sim" oncomplete="modalExclusao.hide()"
	   		actionListener="#{UsuarioMb.excluir}"
	   		update=":formPrincipal :formDados :growl"/>
	   		<p:commandButton value="Não" onclick="modalExclusao.hide()" />
	   	</h:form>
	   	</p:confirmDialog>	
		
	</ui:define>
</ui:composition>